package org.zk.dubbo_provider.service.impl;



import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.Cacheable;
import org.zk.dubbo_provider.dao.CommentMapper;
import org.zk.entity.Comment;
import org.zk.service.CommentService;
import com.alibaba.dubbo.config.annotation.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 评论表 服务实现类
 * </p>
 *
 * @author Alicelonely
 * @since 2019-12-11
 */
@Service(timeout = 10000)
@CacheConfig(cacheNames = "comment")
public class CommentServiceImpl   implements CommentService {

    @Resource
    private CommentMapper commentMapper;


    //分页显示单个课程的评论
    @Override
    public PageInfo getqueryCommentPage(Map<String, Object> map) {
        PageInfo page=new PageInfo();
        int count=commentMapper.getCommentCount(map);
        page.setTotal(count);

        int pageSize = Integer.parseInt(String.valueOf(map.get("pageSize")));
        page.setPageSize(pageSize);
        int currPage = Integer.parseInt(String.valueOf(map.get("pageNum")));
        page.setPageNum(currPage);

        int a ;
        if (count % pageSize > 0) {
            a = count / pageSize + 1;
        } else {
            a = count / pageSize;
        }
        page.setPages(a);

        PageHelper.startPage(currPage, pageSize);
        List ls = commentMapper.queryComment(map);
        page.setList(ls);
        return page;
    }

    //学生评价
    @Override
    public int addComm(Comment comment) {
        return commentMapper.addComm(comment);
    }

    //获取单个课程的评价数量
    @Override
    public int getCommentCount(Map<String, Object> map) {
        return commentMapper.getCommentCount(map);
    }


    public CommentMapper getCommentMapper() {
        return commentMapper;
    }

    public void setCommentMapper(CommentMapper commentMapper) {
        this.commentMapper = commentMapper;
    }
}
